package edu.hawaii.halealohacli.command;

/**
 * A utility class to hold a WattDepot source name and data.
 * 
 * @author Group BackR
 */
public class Rank implements Comparable<Rank> {
  private String name;
  private Double data;
  
  /**
   * Constructs a new WattDepotUtility.
   * @param name Name of source
   * @param data Data of source.
   */
  public Rank(String name, Double data) {
    this.name = name;
    this.data = data;
  }

  /**
   * Returns the name value.
   * @return name
   */
  public String getName() {
    return name;
  }

  /**
   * Returns the data value.
   * @return data
   */
  public Double getData() {
    return data;
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((data == null) ? 0 : data.hashCode());
    result = prime * result + ((name == null) ? 0 : name.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    Rank other = (Rank) obj;
    if (data == null) {
      if (other.data != null) {
        return false;
      }
    }
    else if (!data.equals(other.data)) {
      return false;
    }
    if (name == null) {
      if (other.name != null) {
        return false;
      }
    }
    else if (!name.equals(other.name)) {
      return false;
    }
    return true;
  }
  
  /**
   * Implements the compareTo method to provide a natural ordering.
   * @param e The WattDepotUtility to compare to.
   * @return int The Compare value.
   */
  @Override
  public int compareTo(Rank e) {
    return this.data < e.data ? -1 : this.data > e.data ? 1 : 0;
  }
}
